import { BasicForm } from '@/components/ProForm/interface/index';

import { defaultStyle } from '@/basic/style';
import { ProTableValue } from '@/interface/public';
import { RoleInterface } from '@/api/interface/auth/role';

export function useAddForm(proTableBox: ProTableValue) {
  let addForm = reactive<BasicForm<RoleInterface.ReqSave>>({
    form: {
      id: null,
      name: '',
      remark: '',
      systemId: null
    },
    title: '',
    visible: false,
    formCols: 1,
    options: [
      {
        label: 'id',
        prop: 'id',
        hide: true,
        type: 'input',
        defaultValue: ''
      },
      {
        type: 'input',
        label: '角色名称',
        hide: false,
        prop: 'name',
        defaultValue: '',
        rules: [{ required: true, message: '角色名称不能为空', trigger: 'blur' }]
      },
      {
        type: 'input',
        label: '备注',
        defaultValue: '',
        hide: false,
        prop: 'remark',
        attrs: {
          style: defaultStyle
        }
      }
    ]
  });

  const saveAddForm = async (form: RoleInterface.ReqSave) => {
    await roleSave(form);
    elMessage();
    addForm.visible = false;
    proTableBox.value?.getTableList();
  };
  return { addForm, saveAddForm };
}
